package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.Map;

import db.DBUtil;

public class StudentDao {

	/**
	 * 统计不同性别人数
	 * @throws Exception 
	 */
	public Map<String,Object> queryNumByGender() throws Exception {
		String sql="select gender,count(*) as num from tb_student group by gender";
		Connection conn=DBUtil.getCon();
		PreparedStatement ps=conn.prepareStatement(sql);
		ResultSet rs=ps.executeQuery();
		String[] gender=new String[2];
		Integer[] nums=new Integer[2];
		int i=0;
		while (rs.next()) {
			gender[i]=rs.getString(1);
			nums[i]=rs.getInt(2);
			i++;
		}
		Map<String,Object> stuNum=new HashMap<String, Object>();
		stuNum.put("gender", gender);
		stuNum.put("pNums",nums);
		return stuNum;
	}

}
